<template>
  <el-card>
    <div slot="header" class="header">
      <div class="search-header">
        <span>线上热门搜索</span>
        <el-dropdown>
          <span>
            <i class="el-icon-more"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>黄金糕</el-dropdown-item>
            <el-dropdown-item>狮子头</el-dropdown-item>
            <el-dropdown-item>螺蛳粉</el-dropdown-item>
            <el-dropdown-item>双皮奶</el-dropdown-item>
            <el-dropdown-item>蚵仔煎</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
    <div>
      <el-row :gutter="10">
        <el-col :span="12">
          <LineCharts></LineCharts>
        </el-col>
        <el-col :span="12">
          <LineCharts></LineCharts>
        </el-col>
      </el-row>
      <!-- table表格 -->
      <el-table :data="tableData" style="width: 100%" border>
        <el-table-column label="排名" width="80" type="index">
        </el-table-column>
        <el-table-column label="搜搜关键字" prop="keyword" width="180">
        </el-table-column>
        <el-table-column label="用户数" prop="userNum" sortable>
        </el-table-column>
        <el-table-column label="周涨幅" prop="weekGain" sortable>
        </el-table-column>
      </el-table>
      <!-- 分页去 -->
      <el-pagination
        layout="prev,pager,next,jumper,->,sizes,total"
        :total="tableDatas.length"
        class="pagination"
        style="text-align: center"
        :page-size="limit"
        :current-page="page"
        :page-sizes="[3, 5, 6]"
        @current-change="getSpuList"
        @size-change="handleSizeChange"
      >
      </el-pagination>
    </div>
  </el-card>
</template>

<script>
import LineCharts from "./lineCharts";
export default {
  name: "",
  data() {
    return {
      limit: 3,
      page: 1,
      tableDatas: [
        {
          keyword: "手机",
          userNum: 80,
          weekGain: "15.00%",
        },
        {
          keyword: "KFC",
          userNum: 66,
          weekGain: "13.99%",
        },
        {
          keyword: "张飞张翼德",
          userNum: 36,
          weekGain: "88.31%",
        },
        {
          keyword: "江苏海洋大学",
          userNum: 1,
          weekGain: "-666.66%",
        },
        {
          keyword: "宋跳第一亚索",
          userNum: 888,
          weekGain: "369.15",
        },
        {
          keyword: "江南一枝花",
          userNum: 398,
          weekGain: "651.82%",
        },
        {
          keyword: "你轻轻一个吻",
          userNum: 98,
          weekGain: "29.61%",
        },
        {
          keyword: "芋泥啵啵",
          userNum: 39,
          weekGain: "92.36%",
        },
        {
          keyword: "2014孙大圣",
          userNum: 999999999,
          weekGain: "666666.666666%",
        },
      ],
      tableData: [],
    };
  },
  components: {
    LineCharts,
  },
  mounted() {
    this.getSpuList();
  },
  methods: {
    //当分页器第一页展示数据条数发生变化时
    handleSizeChange(limit) {
      this.limit = limit;
      this.getSpuList();
    },
    //获得当前要展示的页数
    getSpuList(pages = 1) {
      this.page = pages;
      let sum = this.tableDatas.length;
      let list = [];
      let i = 0;
      //计算出每一页是总数据数组的下标的范围，这个范围就是目前要展示的页数
      for (; i < sum; i++) {
        if (
          i >= (this.page - 1) * this.limit &&
          i < (this.page - 1) * this.limit + this.limit
        ) {
          list.push(this.tableDatas[i]);
        }
      }
      this.tableData = list;
    },
  },
};
</script>

<style scoped>
.header {
  border-bottom: 1px solid #eee;
  padding: 5px 0px;
}
.search-header {
  display: flex;
  justify-content: space-between;
}
.pagination {
  float: right;
}
</style>